package logic

import (
	"context"
	"library/models/mysql"

	"library/libraryrpc/internal/svc"
	"library/libraryrpc/libraryrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type LabelAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLabelAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LabelAddLogic {
	return &LabelAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LabelAddLogic) LabelAdd(in *libraryrpc.LabelAddRequest) (*libraryrpc.LabelAddResponse, error) {
	// todo: add your logic here and delete this line
	label := mysql.Label{
		Name:          in.Name,
		Content:       in.Content,
		UserId:        int(in.UserId),
		InformationId: int(in.InformationId),
	}
	mysql.DB.Create(&label)
	return &libraryrpc.LabelAddResponse{
		Label: int64(label.ID),
	}, nil
}
